Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

218
Visualizações
Is there a way to compare "\x3C!--" with "<!--" and get 'true' in JavaScript?

In one of my projects I have to parse HTML pages and to check if each parsed "tag candidate" is in the predefined list of tag defining strings.

The problem emerges when for some reason the parser returns "\x3C!--" as the "tag candidate", so I get false when comparing it with "<!--" from the list.

Is there any way to get true comparing those strings?

UPDATE:

To clarify my question and to explain where the error occurs I add two screenshots from DevTools panel, Google Chrome, version 104.0.5083.0 (Official Build) dev (64-bit).

Paused in debugger 1

We can see that the value of nodeParse.tagOpening is changed almost immediately after it has been assigned. It's quite strange.

Paused in debugger 2

But it's even more strange that if I open properties of nodeParse object in Local Scope, the correct (initially assigned) value is shown for tagOpening.

So it seems the browser knows that both shown values are actually equivalent, but for some reason distinguishes them. Any comments?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Within a HTML document <!-- is the opening delimiter for comments, even within <script> tags, see HTML-like Comments, so I would avoid including it as a string in your code.

Instead, you could just use the hex escape sequence in the tag-defining string in the first place. For example:

nodeParse.tagOpening = '\x3C!--';
nodeData.tagStarter = '\x3C!--';
about 4 years ago · Juan Pablo Isaza Relatório

0

After a deeper investigation I have revealed that "\x3C!--" == "<!--" is always true, with no extra efforts (see the screenshot below).

We should keep in mind however that string "<!--" (and any longer one) is stored as is in a variable, but is transformed into "\x3C!--" when is stored in an object's property. At least in Google Chrome.

So we should assign the object's property to a variable (like var s2 = ob.a;), if we want to get value "<!--" back for sure. It was not known to me, so I have made a mistake in my code.

Paused in debugger 3

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda